package cn.yunyichina.provider.pay.utils;

import cn.yunyichina.utils.commons.RandomUtil;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * Created by Lullaby on 2016/10/25.
 */
public class NumberUtil {

    private static final DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    /**
     * 构建云医支付流水号
     *
     * @return
     */
    public static String buildPaymentDealNo() {
        return formatter.format(
                Calendar.getInstance().getTime()
        ).concat(
                RandomUtil.getRandomNumberChar(7)
        );
    }


    /**
     * 将分为单位的转换为元,且格式化千分位（除100）
     *
     * @param amount
     * @return
     * @throws Exception
     */
    public static String changeF2Y(String amount){
        NumberFormat nf = new DecimalFormat("#,###.####");
        Double money = Double.valueOf(BigDecimal.valueOf(Long.valueOf(amount)).divide(new BigDecimal(100)).toString());
        return nf.format(money);
    }

}
